import 'package:kkhousekeep/page/me/set_password_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:kkhousekeep/widget/custom_form_textfield.dart';

import '../../widget/custom_app_bar.dart';
import '../../widget/custom_button.dart';
import '../../widget/setting_section.dart';

class SetPasswordPage extends StatelessWidget {
  const SetPasswordPage({super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder<SetPasswordController>(
      init: SetPasswordController(),
      builder: (controller) => Scaffold(
        appBar: CustomAppBar("设置密码"),
        body: Container(
          padding: EdgeInsets.only(top: 16.h),
          color: const Color(0xFFf4f5f6),
          child: SafeArea(
            left: false,
            right: false,
            child: Obx(
              () => Column(
                children: [
                  SettingSectionItem(
                    title: "用户名",
                    titleStyle: const TextStyle(color: Color(0xFF6D6D6D)),
                    isShowArrow: false,
                    rightWidget: Text(
                      controller.username.value,
                      style: TextStyle(
                        fontSize: 32.sp,
                        color: const Color(0xFF333333),
                      ),
                    ),
                  ),
                  SettingSectionItem(
                    title: "原密码",
                    titleStyle: const TextStyle(color: Color(0xFF6D6D6D)),
                    isShowArrow: false,
                    rightWidget: Expanded(
                      child: CustomFormTextField(
                        obscureText: true,
                        textInputAction: TextInputAction.next,
                        text: controller.oldPassword.value,
                        isShowClearBtn: false,
                        textAlign: TextAlign.end,
                        controller: controller.oldPwdController,
                        hintText: "请写原密码",
                      ),
                    ),
                  ),
                  SettingSectionItem(
                    title: "新密码",
                    titleStyle: const TextStyle(color: Color(0xFF6D6D6D)),
                    isShowArrow: false,
                    rightWidget: Expanded(
                      child: CustomFormTextField(
                        obscureText: true,
                        textInputAction: TextInputAction.next,
                        text: controller.newPassword.value,
                        isShowClearBtn: false,
                        textAlign: TextAlign.end,
                        controller: controller.newPwdController,
                        hintText: "请写新密码",
                      ),
                    ),
                  ),
                  SettingSectionItem(
                    title: "确认密码",
                    titleStyle: const TextStyle(color: Color(0xFF6D6D6D)),
                    isShowArrow: false,
                    rightWidget: SizedBox(
                      width: 300.w,
                      child: CustomFormTextField(
                        obscureText: true,
                        textInputAction: TextInputAction.done,
                        controller: controller.newPwdConfirmController,
                        text: controller.newPasswordConfirm.value,
                        isShowClearBtn: false,
                        textAlign: TextAlign.end,
                        hintText: "再次填写确认",
                      ),
                    ),
                  ),
                  Text(
                    "注：密码必须是至少6位英文+数字组合！",
                    style: TextStyle(
                      fontSize: 28.sp,
                      color: const Color(0xFF999999),
                    ),
                  ).marginOnly(top: 16.h),
                  const Spacer(),
                  CustomButton(
                      text: "保存",
                      isAsh: controller.isAsh.value,
                      width: 420.w,
                      height: 90.h,
                      onPressed: () {
                        controller.checkAndSave();
                      }).marginOnly(bottom: 60.h),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}
